import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { CpasIcon, DevPopup, LayoutB } from '../../../public/cpas-ui';
import AntTabs from '~/public/cpas-ui/components-ui/ant-components/AntTab';
import { Button } from 'devextreme-react/button';
import TreeView from "devextreme-react/tree-view";
import { getPaperList } from "~/src/pages/AuditPaper/service";
import { getApiData } from "../../services/cpasRequest"; // 附注导出，
import { getLeftTreeList } from "../reportAnalysis/tab1/server"
import { exportTemplate, getAccountAdujustList, getDesignTabelEditDate, getDesignTabelEditDateCompare, getdgfjList, zip } from "./server";
import TreeList, { Column, Selection } from "devextreme-react/tree-list";
import PubSub from 'pubsub-js'
import { LoadPanel } from 'devextreme-react/load-panel';
import { Modal, Progress, Tooltip, } from 'antd';
import { history } from 'umi';
import notify from "devextreme/ui/notify";
import SelectBox from "devextreme-react/select-box";
import { getJson, formatterChinaTime } from '@/utils';
import AudTabPage from '~/src/components/PageTab/AudTabPage';
import { getAccountInfo, getDateList } from '@/pages/home/components/SetDataGrid/service';
import { getReportList } from '@/pages/batchSettings/service';
import { getInformationList } from '@/pages/home/components/group-part/service';
import { getVersions } from "../reportBuilder/service";
// import { useModel } from "@/.umi/plugin-model/useModel";
import {
    DataGrid
} from 'devextreme-react/data-grid';
import { useModel } from 'umi';
const ReportExport = (props: any) => {
    type firstTitleType = { id: number, items?: [], isselected?: boolean, name: string, selected: boolean }[];
    const { initialState } = useModel('@@initialState');
    const { dbname, sjxmbh, zcbfid, sjnd, zcbfName } = initialState?.curPart;
    const [firstTitle, setfirstTitle] = useState<firstTitleType>([]);
    const [secondTitle, setsecondTitle] = useState<firstTitleType>([]); // 第二栏目的显示标题
    const selectedDisclosureTable = useRef([]); // 选中的DisclosureTable
    const [currentid, setcurrentid] = useState(0);  // 当前选中的DisclosureTable的id
    const [zcbf, setzcbf] = useState<{ accountDate: [], accountDateSet: [], zcbfinfo: {} }>();
    
  
    const [msg, setMsg] = useState("");
    const notes = useRef<any>(false || []);
    const auditAjust = useRef<any>(false || []);
  
    const [reportData, setreportData] = useState([]);// 接口返回的数据临时保存，和report的区别是，report用于最后的结果的传输
    const [isexport, setIsexport] = useState(false);
    const [dgdatalist, setDgdatalist] = useState([]); // 当前的渲染的数据列表
    const [versionList, setVersionList] = useState(["全部"]); // 账套
    const [isMaskOpen, setIsMaskOpen] = useState(true);
    const [ProgressInfoVisible, setProgressInfoVisible] = useState(false);
    const [ProgressInfoValue, setProgressInfoValue] = useState<number>();
    const [loadPanelVisible, setLoadPanelVisible] = useState(false);
    const [auditAdjustFiterAccountDate, setAuditAdjustFiterAccountDate] = useState(0);
    const [auditAdjustFiterBiilType, setAuditAdjustFiterBiilType] = useState(-1);
    const [TapActiveKey, setTapActiveKey] = useState("1");
    // 财务数据单独存储
    const [Trial, setTrial] = useState([{ name: "未审财务报表", id: 1, selected: false, isselected: false }, { name: "审定财务报表", id: 2, selected: false, isselected: false }, { name: "试算平衡表", id: 3, isselected: false, selected: false }]);
    const showDataRef = useRef<any>({
        data_id: '',
        billType: -1
    });
 
    const report = useRef<string[]>([]);
    const selectTrial = useRef<string[]>([]);
    // 底稿附注单独存储
    const TapActiveKeydgOrfj = useRef<any>({
        key: "1",
        dg: [],
        selectFj: [],
        selectdg: []
    });
    const treeViewRef = useRef<any>(null);
    enum leftTitleList {
        zcfb = 1,
        dgfj = 2,
        auditAdjust = 3,
        notes = 4,
        report = 5
    }
    // 页面渲染后执行
    // 判断有没有导出的项目，渲染选中的状态
    useEffect(() => {
        // console.log(initialState, "initialState")
        LeftOneTitleView()
        setLoadPanelVisible(true);
        let index = 0
        PubSub.subscribe('call_progress', (msg, data: { count: number,msg: string }) => {
            index = index + 1
            console.log(data, "data")
            setProgressInfoValueEvent(index, data.count)
            setMsg(data.msg)
        })
    }, []);
    // 第一步
    const LeftOneTitleView = async () => {
        // 渲染侧边栏，同时渲染第一个侧边栏，侧边栏的逻辑遍历，可能没有的（报告底稿，附件），，同时也把默认导出的都渲染了，同时还要遍历是否第一个渲染第二栏目
        let config = (await getJson('resultMenu', './')) as any;
        let Indexid = 0 // 定义第一个id，默认是1
        config = config.exportFirstIndex
        // 是否选中处理
        for (let a of config) {
            a.isselected = true
            if (a.id === 5) {
                let reportV = await initVersions({ projectId: sjxmbh, partId: zcbfid })
                if (reportV.length) {
                    config[Indexid].isselected = true
                    config[Indexid].selected = true
                    // 第二栏目初次渲染的问题，是默认当前版本，还是历史版本
                    if (reportV.length > 1) {
                        config[Indexid].items[1].isselected = true;
                        config[Indexid].items[1].selected = true;
                        config[Indexid].items[0].isselected = true;
                        config[Indexid].items[0].selected = true;
                    } else {
                        config[Indexid].items[0].isselected = true;
                        config[Indexid].items[0].selected = true;
                    }
                    // 导出存储
                    report.current=reportV
                    setreportData(reportV)
                } else {
                    config[Indexid].isselected = false
                    config[Indexid].selected = false
                }
                if (config[0].id === 5) {
                }
            }
            // 附注和底稿，必然存在一个，只要有一个有就渲染选中的状态
            if (a.id === leftTitleList.dgfj) {
                let isSelect = false
                for (let b of a.items) {
                    if (b.id === 21) {
                        let dglist = await getdglist()
                        if (dglist?.length) {
                           let dgfjlist = await getdgfjList({dbname: zcbfid,dgid:dglist.map((a:any)=> `'${a.id}'`).join(',')})
                           TapActiveKeydgOrfj.current.dgfj = dgfjlist;
                           TapActiveKeydgOrfj.current.slectdgfj=dgfjlist;
                           console.log(dgfjlist)
                            isSelect = true
                        }
                    }
                    if (b.id === 22) {
                        const res = await getApiData('dgfj.list', { dbname: zcbfid });
                        let tem = res.data.map((a: any) => {
                            return { name: a.fjName + a.fjlx, id: a.fjid, editDate: formatterChinaTime(a.LastEditDate), editUser: a.UserName, selected: true }
                        }
                        )
                        TapActiveKeydgOrfj.current.selectFj = tem // 存储选中的id附件id
                        TapActiveKeydgOrfj.current.fj = tem
                        // setdjfj(tem)
                        if (tem.length) {
                            isSelect = true
                        }
                    }
                }
                if (isSelect) {
                    config[Indexid].isselected = true
                    config[Indexid].selected = true
                } else {
                    config[Indexid].isselected = false
                    config[Indexid].selected = false
                }
                // 首页问题
                if (config[0].id === 2) {
                }
            }
            if (a.id === leftTitleList.auditAdjust) {
                let res = await getAccountInfo({ dbname: zcbfid })
                // console.log(res.map(a=>`[${a.Data_ID}]${zcbfName}`),"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww")
                setVersionList([{ Data_ID: 0, name: "全部" }, ...res.map((a: { Data_ID: any; }) => {
                    return {
                        Data_ID: a.Data_ID, name: `${a.Data_ID}`
                    }
                })])
                let AccountAdujustListData = await getAccountAdujustInfo({ DataId: 0, billType: -1 })
                if (AccountAdujustListData.length > 0) {
                    config[Indexid].isselected = true
                    config[Indexid].selected = true
                    // 渲染第二栏目
                    config[Indexid].items = AccountAdujustListData
                } else {
                    config[Indexid].isselected = false
                    config[Indexid].selected = false
                }
                // 
            }
            if (a.id === leftTitleList.notes) {
                // 读取的的是数据库表
                let table_list = await getDesignTabelEditDate({ dbName: zcbfid })
                if (table_list.data.length > 0) {
                    if (table_list.data.filter((a: any) => a.type === 'ds').length > 0) {
                        let note = await getDesignTabelEditDateCompare({ zcbfid: zcbfid, sjnd: sjnd, table_list: table_list.data.filter((a: any) => a.type === 'ds') })
                        if (note.length) {
                            config[Indexid].isselected = true
                            config[Indexid].selected = true
                            // 渲染第二栏目
                            config[Indexid].items = note
                            //导出存储
                            notes.current = note
                        }
                    }
                    if (table_list.data.filter((a: any) => a.type === 'fs').length > 0) {
                        config[Indexid].isselected = true
                        config[Indexid].selected = true
                        let tempTrial: any = []
                        if (table_list.data.filter((a: any) => a.type === 'fs' && a.name.includes("审定财务")).length > 0) {
                            tempTrial = Trial.map((a: any) => {
                                if (a.id === 2) {
                                    return {
                                        ...a,
                                        isselected: true,
                                        selected: true
                                    }
                                } else {
                                    return a;
                                }
                            })
                        }
                        if (table_list.data.filter((a: any) => a.type === 'fs' && a.name.includes("未审财务报表")).length > 0) {
                            tempTrial = tempTrial.map((a: any) => {
                                if (a.id === 1) {
                                    return {
                                        ...a,
                                        isselected: true,
                                        selected: true
                                    }
                                } else {
                                    return a;
                                }
                            })
                        }
                        if (table_list.data.filter((a: any) => a.type === 'fs' && a.name.includes("试算平衡")).length > 0) {
                            tempTrial = tempTrial.map((a: any) => {
                                if (a.id === 3) {
                                    return {
                                        ...a,
                                        isselected: true,
                                        selected: true
                                    }
                                } else {
                                    return a;
                                }
                            })
                        }
                        selectTrial.current = tempTrial
                        setTrial(tempTrial)
                    }
                } else {
                }
            }
            if (a.id === leftTitleList.zcfb) {
                // 判断基础信息有，期间设置，默认就去请求，导出的时候判断选中状态，基础部分，永远导出，没有选中导出，却依然可以导入，那任何时候都带有基础部分，怎么解释的问题
                let zcbfinfo = await getInformationList({ zcbfid: zcbfid })
                if (zcbfinfo.length && zcbfinfo[0].ReceivePerson) {
                    setzcbf({ ...zcbf, zcbfinfo: zcbfinfo[0], accountDate: [], accountDateSet: [] })
                } else {
                    config[Indexid].items[0].isselected = false
                    config[Indexid].items[0].selected = false
                }
            }
            Indexid = Indexid + 1;
        }
        // 渲染左边第一栏目
        setfirstTitle(config)
        // 第二栏固定显示
        leftonItemsChange({ itemIndex: 0 }, config);
        hideLoadPanel()
    }
    const setProgressInfoValueEvent = (data: any, count: any) => {
        // let count = firstTitle.filter((a:any)=>a.selected==true).length
        setProgressInfoValue(((data / count) * 100).toFixed(2) as any)
    }
    // 渲染二级栏目,用一级栏目点击事件去渲染，首次进去手动执行次函数，手动执行此函数时，
    const leftonItemsChange = async (Event: any, config: firstTitleType) => {
        // 渲染第二栏目分两种情况，手动渲染和点击渲染
        // 点击渲染，之传点击id，根据点击id去state查找数据渲染，
        // 手动渲染，根据参数渲染
        // 第二栏目的渲染必须有判断，第一栏目为空，那么第二栏目不显示选中,
        // 第二栏的显示逻辑，不为空的，调用接口的，根据接口返回显示，不调接口的固定显示，
        // 
        setTapActiveKey("1")
        setsecondTitle(config[Event.itemIndex].items as [])
        // 获取当前的一级栏目id,为了控制二级栏目显示的组件
        setcurrentid(config[Event.itemIndex].id)
    }
    // 报告部分获取数据
    async function initVersions(p: any) {
        const data = await getVersions(p);
        return data.data as [];
    }
    const hideLoadPanel = useCallback(() => {
        setLoadPanelVisible(false);
        // setEmployeeInfo(employee);
    }, [setLoadPanelVisible]);
    // 底稿部分获取数据并渲染
    const getdglist = async () => {
        let dglist = (await getPaperList({ dbname: zcbfid, zcbfid: zcbfid, sjjd: "" })).data.filter((a: { dgzt: number; }) => a.dgzt > 0 && a.dgzt < 201)
        // debugger
        if (dglist.length) {
            let res = dglist.map((a: any) => {
                return { name: a.dgmc + a.dglx, editDate: formatterChinaTime(a.editDate), editUser: a.editUser, id: a.dgid, url: a.url, selected: true, dgnd: a.dgnd }
            })
            setDgdatalist(res)
            // setdj(res)
            TapActiveKeydgOrfj.current.selectdg = res
            TapActiveKeydgOrfj.current.dg = res
            return res
        } else {
            setDgdatalist([]);
            return []
        }
    }
    //底稿部分切换
    const dgChangeTabsKey = async (e: any) => {
        // 数据在进去时获取，这一块是激活哪个tab显示
        if (e === '1') {
            TapActiveKeydgOrfj.current.key = "1"
            //  重新渲染，取接口返回的原始数据
            setDgdatalist(TapActiveKeydgOrfj.current.dg)
        } else {
            TapActiveKeydgOrfj.current.key = "2"
            setDgdatalist(TapActiveKeydgOrfj.current.fj)
        }
    }
    // 附注部分切换
    const notechangeTabsKey = async (e: any) => {
        if (e === '1') {
            setTapActiveKey("1")
            leftonItemsChange({ itemIndex: leftTitleList.notes - 1 }, firstTitle)
        } else {
            setTapActiveKey("2")
            setsecondTitle(Trial)
        }
    }
 
    const treeViewSelectionChanged = (e: { component: any; }) => {
        syncSelection(e.component);
    };
    const syncSelection = (treeView: { getSelectedNodes: () => any[]; }) => {
        const selectedEmployees = treeView
            .getSelectedNodes()
            .map((node: { itemData: any; }) => node.itemData);
        // 定位不同的目录记住不同的选择 TwotreeViewSelectionChanged
        selectedDisclosureTable.current = selectedEmployees as [];
        // 可能没有的项目，报告底稿，附件
        if (selectedEmployees.filter(a => { a.id === 5 || a.id === 2 }).filter(a => a.selected !== a.isselected).length) {
            notify(`此项目【${selectedEmployees[0].name}】下没有成果数据，该项目不会被导出`, 'error', 1000);
        }
        // console.log(selectedEmployees, selectedEmployees.filter(a => { a.id === 5 }));
        // 控制导出按钮
        if (selectedEmployees.length === 0) {
            setIsexport(true)
        } else {
            setIsexport(false)
        }
    };
    const TwotreeViewSelectionChanged = (e: { component: any; }) => {
        TwosyncSelection(treeViewRef.current.instance.getSelectedNodes(), treeViewRef.current.instance.getNodes())
    };
    const TwosyncSelection = async (getSelectedNodes: [], getNodes: []) => {
        const selectedEmployees = getSelectedNodes
            .map((node: { itemData: any; }) => node.itemData);
        // 如果没有进行提示,isselected 标记真的没有，是true
        if (selectedEmployees.filter(a => a.selected === true && a.isselected === false).length) {
            notify("此选项中没有数据，无法被导出，请重新选择", 'error', 2000);
        }
        // 定位不同的目录记住不同的选择 TwotreeViewSelectionChanged
        if (currentid === leftTitleList.zcfb) {
            if (selectedEmployees.filter((a: any) => a.id === 12).length == 0) {
                // setAccountDate({})
            }
        } if (currentid === leftTitleList.dgfj) {
        } if (currentid === leftTitleList.auditAdjust) {
            auditAjust.current = selectedEmployees as []
            // setauditAjust(selectedEmployees as [])
        } if (currentid === leftTitleList.notes) {
            // 试算，数据源不一样
            if (TapActiveKey === "1") {
                notes.current = selectedEmployees as []
            }
            if (TapActiveKey === "2") {
                // 
                selectTrial.current=selectedEmployees
            }
        } if (currentid === leftTitleList.report) {
            // 传数组【】文件目录，在此转换，存的时候，也带存历史数据数组【"gen","111"】
            // console.log(selectedEmployees)
            if (selectedEmployees.length === 1) {
                if (selectedEmployees[0].id === 52) {
                    report.current =reportData.filter(a => a !== "Generated")
                  
                } else {
                   
                    report.current =["Generated"]
                }
            } else if (selectedEmployees.length === 2) {
                report.current =reportData
            }
            else {
                report.current =[]
            }
        }
    };
    const exportResult = async () => {
        console.log(notes, firstTitle, report.current)
        // let zcbfPartInfo
        // 只做一级节点了，应该是一级节点和二级节点一起判断，一节点选中的，且对应的二级节点也有选中就可以导出
        let isSelect = firstTitle.filter((a: any) => {
            if (a.isselected && a.selected) {
                if (a.items && a.items.length > 0 && a.id != leftTitleList.dgfj) {
                    if (a.items.filter((b: any) => {
                        if (b.isselected && b.selected) {
                            return true
                        } else {
                            return false
                        }
                    }).length > 0) {
                        return true
                    } else {
                        return false
                    }
                } else {
                    return false
                }
            } else {
                return false
            }
        })
        if (isexport || (isSelect.length === 0 && TapActiveKeydgOrfj.current.selectFj.length === 0 && TapActiveKeydgOrfj.current.selectdg.length === 0)) {
            notify("没有可以导出的成果数据", 'error', 2000);
            return;
        }
        // 全部导出，加载首次进去时没有渲染，
        // 处理默认全部导出加载的,且配置了次项目
        // 只要一级选中，如果一级没有选中不导出是有问题的
        if (firstTitle.filter(a => a.id === leftTitleList.zcfb)) {
            // zcbfPartInfo = await getAccoutInfo()
        }
        // 全部数据和 获取勾选的数据
        // 一个表按照按渲染字段对应
        //@ts-ignore
        const dialog_result = await window.electronComponents.showSaveDialog("aum6", `(${zcbfid})${zcbfName}-项目成果.aum6`);
        if (dialog_result.canceled) {
            return;
        }
        const file_path = dialog_result.filePath;
        //获取栏目参数
        //@ts-ignore
        let tempPath = window.main.mainObject.getAppPath() + "\\Temp\\";
        setProgressInfoVisible(true)
        setLoadPanelVisible(true)
        let res= await exportTemplate(file_path, zcbfid, sjxmbh,
            //获取栏目参数，默认全部，全部取消，无法导出
            selectedDisclosureTable.current.length === 0 ? firstTitle : selectedDisclosureTable.current,
            //firstTitle,
            // 底稿参数，默认全部，全部是布尔，全部取消，也无法导出是【】
            { ...zcbf },
            TapActiveKeydgOrfj.current.selectdg,
            TapActiveKeydgOrfj.current.selectFj,
            TapActiveKeydgOrfj.current.slectdgfj,
            auditAjust.current,
            // 附注
            notes.current,
            report.current,
            sjnd,
            selectTrial.current,
            versionList.filter((a: any) => a.name !== '全部'),// 账套
            [],
            []
        );
        console.log(res)
        
        if (!res) {
            notify("导出成果失败", 'error', 2000);
            return;
        }
        setProgressInfoValue(100)
        setMsg("导出完成，压缩中...")
      
        await zip({ src: tempPath, targetDir: file_path })
        setLoadPanelVisible(true)
     
        setProgressInfoVisible(false)
        notify("导出成果成功", 'success', 2000);
        setIsMaskOpen(false)
        const audTabpage = AudTabPage.getInstance();
        audTabpage.closeTab('closeCur');;
        history.push(audTabpage.activeTabKey);

    }
    const getAccountAdujustInfo = async ({ DataId, billType }: { DataId: any, billType: any }) => {
        let config: [] = [];
        let p: {} = { dbname: zcbfid }
        if (billType != -1) {
            p = { ...p, billType: billType }
        }
        if (DataId != 0) {
            p = { ...p, Data_ID: DataId }
        }
        let AccountAdujustListData = await getAccountAdujustList(p)
        let uniqueAccountAdujustListData = AccountAdujustListData.data.reduce((acc: any, curr: { GroupInfo: any; }) => {
            const index = acc.findIndex((item: { GroupInfo: any; }) => item.GroupInfo === curr.GroupInfo)
            if (index < 0) {
                acc.push(curr)
            }
            return acc
        }, [])
        if (AccountAdujustListData.data.length > 0) {
            // 渲染第二栏目
            config = uniqueAccountAdujustListData.map((a: {
                BillType: any;
                EditDate: any;
                Data_ID: any; GroupInfo: any; BillID: any;
            }) => { return { name: a.GroupInfo, selected: true,isselected:true, BillID: a.BillID, Data_ID: a.Data_ID, EditDate: a.EditDate, BillType: a.BillType } }) as []
            auditAjust.current=config
        } else {
            auditAjust.current=[]
        }
        return config
    }
    // 底稿附件点击记录
    const TwotreeListSelectionChanged = useCallback((e: any) => {
        const selectedData = e.component.getSelectedRowsData();
        // 存选中的id，为了再次的切换回来显示
        // 存选中的信息，为了导出数据时方便
        if (TapActiveKeydgOrfj.current.key === "1") {
            TapActiveKeydgOrfj.current.selectdg = selectedData
            console.log(TapActiveKeydgOrfj.current.dgfj,selectedData)
            TapActiveKeydgOrfj.current.slectdgfj=TapActiveKeydgOrfj.current.dgfj.filter( (a:any)=>{
                return selectedData.filter((b:any)=>{
                    return a.dgid===b.id
            }          ).length>0       
            })
            console.log(TapActiveKeydgOrfj.current.slectdgfj)
        } else {
            // 保存选中记录
            TapActiveKeydgOrfj.current.selectFj = selectedData
        }
    }, []);
    const AuditAjustHead = () => {
        return (<div style={{ display: 'flex', alignItems: 'center', marginLeft: 10 }}> <div style={{ whiteSpace: 'nowrap' }}>套账：</div>
            <SelectBox
                width={100}
                items={versionList}
                defaultValue={auditAdjustFiterAccountDate}
                displayExpr='name'
                valueExpr='Data_ID'
                onValueChange={async (value) => {
                    showDataRef.current.data_id = value;
                    setAuditAdjustFiterAccountDate(value)
                    let res = await getAccountAdujustInfo({ DataId: value, billType: showDataRef.current.billType })
                    setsecondTitle(res)
                }}
            />
            <div style={{ whiteSpace: 'nowrap', marginLeft: 5 }}>单据类型：</div>
            <SelectBox
                width={100}
                items={[{ id: -1, name: "全部" }, { id: 0, name: "账表调整" }, { id: 1, name: "审计调整" }]}
                defaultValue={auditAdjustFiterBiilType}
                displayExpr='name'
                valueExpr='id'
                onValueChange={async (value) => {
                    showDataRef.current.billType = value;
                    setAuditAdjustFiterBiilType(value)
                    let res = await getAccountAdujustInfo({ DataId: showDataRef.current.data_id, billType: value })
                    setsecondTitle(res)
                }}
            />
        </div>
        )
    }
    const LeftOne = () => {
        return <TreeView
            id="treeview"
            width={'100%'}
            height={'calc(100vh - 250px)'}
            dataStructure="plain"
            onItemClick={(e) => leftonItemsChange(e, firstTitle)}
            items={firstTitle}
            displayExpr="name"
            keyExpr="id"
            selectByClick={false}
            // selectAllText="全选"
            showCheckBoxesMode={'normal'}
            virtualModeEnabled={true}
            selectionMode={'multiple'}
            selectNodesRecursive={false}
            onSelectionChanged={treeViewSelectionChanged}
        ></TreeView>
    }
    const LeftTwo = () => {
        return <TreeView
            id="treeview"
            width={'100%'}
            height={'calc(100vh - 250px)'}
            dataStructure="plain"
            ref={treeViewRef}
            parentIdExpr="pid"
            items={secondTitle}
            displayExpr={"name"}
            keyExpr="id"
            rootValue={""}
            selectByClick={true}
            selectAllText="全选"
            showCheckBoxesMode={'selectAll'}
            virtualModeEnabled={true}
            selectionMode={'multiple'}
            selectNodesRecursive={false}
            onSelectionChanged={TwotreeViewSelectionChanged}
        ></TreeView>
    }
    const LeftDatatable = () => {
        //@ts-ignore
        return <DataGrid
            id="treelist"
            width={'100%'}
            height={'calc(100vh - 250px)'}
            dataStructure="plain"
            dataSource={dgdatalist}
            parentIdExpr="pid"
            keyExpr="id"
            rootValue={""}
            showRowLines={true}
            showBorders={true}
            columnAutoWidth={true}
            defaultSelectedRowKeys={TapActiveKeydgOrfj.current.selectdg.map((a: any) => a.id)}
            onSelectionChanged={TwotreeListSelectionChanged}
        >
            <Selection recursive={true} allowSelectAll={true} mode="multiple" />
            <Column dataField="dgnd" caption="年份" dataType="string" groupIndex={0} />
            <Column
                dataField="name"
                caption="项目"
            />
            <Column
                dataField="editDate"
                caption="修改日期"
            />
            <Column
                dataField="editUser"
                caption="编辑人"
            />
        </DataGrid>
    }
    const LeftDatatablefj = () => {
        //@ts-ignore
        return <DataGrid
            id="treelist"
            width={'100%'}
            height={'calc(100vh - 250px)'}
            dataStructure="plain"
            dataSource={dgdatalist}
            parentIdExpr="pid"
            keyExpr="id"
            rootValue={""}
            showRowLines={true}
            showBorders={true}
            columnAutoWidth={true}
            defaultSelectedRowKeys={TapActiveKeydgOrfj.current.selectFj.map((a: any) => a.id)}
            onSelectionChanged={TwotreeListSelectionChanged}
        >
            <Selection recursive={true} allowSelectAll={true} mode="multiple" />
            <Column
                dataField="name"
                caption="项目"
            />
            <Column
                dataField="editDate"
                caption="修改日期"
            />
            <Column
                dataField="editUser"
                caption="编辑人"
            />
        </DataGrid>
    }
    const RightLayt = () => {
        switch (currentid) {
            case 2:
                return <div  style={{ marginLeft: '10px', marginRight: '8px' }}>
                    <AntTabs
                        activeKey={TapActiveKeydgOrfj.current.key}
                        onChange={(val: string) => { dgChangeTabsKey(val) }}
                        destroyInactiveTabPane={false}
                        type="card"
                    >
                        <AntTabs.TabPane key="1" type="1" tab="底稿"><LeftDatatable /></AntTabs.TabPane> <AntTabs.TabPane type="1" key="2" tab="附件"><LeftDatatablefj /></AntTabs.TabPane>
                    </AntTabs></div>
            case leftTitleList.auditAdjust:
                return <div  style={{ marginLeft: '10px', marginRight: '8px' }}>  {useMemo(() => { return <AuditAjustHead /> }, [showDataRef.current.billType])}     <LeftTwo /></div>
            case leftTitleList.notes:
                return <div  style={{ marginLeft: '10px', marginRight: '8px' }}>
                    <AntTabs
                        activeKey={TapActiveKey}
                        onChange={(val: string) => { notechangeTabsKey(val) }}
                        destroyInactiveTabPane={false}
                        type="card"
                    >
                        <AntTabs.TabPane key="1" type="1" tab="附注"><LeftTwo /></AntTabs.TabPane> <AntTabs.TabPane type="1" key="2" tab="财务"><LeftTwo /></AntTabs.TabPane>
                    </AntTabs></div>
            default:
                return <div  style={{ marginLeft: '10px', marginRight: '8px' }}> <LeftTwo /></div>
        }
    }
    // 全局左右布局
    //@ts-ignore
    return <Modal title="项目成果导出" onOk={exportResult}
        onCancel={() => {
            const audTabpage = AudTabPage.getInstance();
            audTabpage.closeTab('closeCur');;
            history.push(audTabpage.activeTabKey);
            PubSub.clearAllSubscriptions();
            setIsMaskOpen(false)
        }} open={isMaskOpen} keyboard={true} maskClosable={false} centered={true} closable={true} width={'80%'} destroyOnClose={true} forceRender={true} okText='导出'>
        <LayoutB
            rowSize={['15%', '150px', '90%']}
            leftSlot={
                <div  ><LeftOne /></div>
            }
            rightSlot={
                <><RightLayt /></>
            }
        >
        </LayoutB>
        <LoadPanel
            shadingColor="rgba(0,0,0,0.4)"
            position="center"
            onHiding={hideLoadPanel}
            visible={loadPanelVisible}
            showIndicator={true}
            shading={true}
            showPane={true}
            message={msg}
        />
        {ProgressInfoVisible ? <Tooltip popupVisible={false} title="">
            <Progress percent={ProgressInfoValue} />
        </Tooltip> : <></>}
    </Modal>
}
export default ReportExport;
